/**
 * 冒泡排序
 *
 * @param {number[]} nums
 * @return {number[]}
 */
function bubbleSort(nums) {
  const length = nums.length;
  if (length < 2) {
    return nums;
  }
  let modify;
  let temp;
  for (let i = 0; i < length; i++) {
    modify = false;
    for (let j = 1; j < length - i; j++) {
      if (nums[j - 1] > nums[j]) {
        temp = nums[j];
        nums[j] = nums[j - 1];
        nums[j - 1] = temp;
        modify = true;
      }
    }
    if (!modify) {
      break;
    }
  }
  return nums;
}

const nums = [3, 44, 38, 5, 47, 15, 36, 26, 27, 2, 46, 4, 19, 50, 48];
console.log(bubbleSort(nums));
